package com.guigu.ssm.controller;

import com.guigu.ssm.pojo.Student;
import com.guigu.ssm.serivce.StudentService;
import com.guigu.ssm.utils.PageVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Map;

@RestController
@RequestMapping("stu")
public class StuController {
    @Autowired
    StudentService studentService;

    @PostMapping
    @ResponseBody
    public PageVo<Student> findStuList(@RequestBody Map<String,String> map,Student student){
        String ename = map.get("ename");
        String job = map.get("job");
        String deptno = map.get("deptno");
        student.setEname(ename);
        student.setJob(job);
        student.setDeptno(deptno);
        return studentService.findStuLimit(Integer.valueOf(map.get("page")), Integer.valueOf(map.get("pageNum")),student);
    }

    @RequestMapping("/insert")
    @ResponseBody
    public int add(HttpServletRequest request, HttpServletResponse response,Student student){
        String ename = request.getParameter("ename1");
        System.out.println(ename);
        String job = request.getParameter("job1");
        String sal = request.getParameter("sal1");
        String hiredate = request.getParameter("hiredate1");
        String deptno = request.getParameter("deptno1");
        student.setEname(ename);
        student.setJob(job);
        student.setSal(sal);
        student.setHiredate(hiredate);
        student.setDeptno(deptno);
        int insert = studentService.insert(student);
        return insert;
    }

    @DeleteMapping(value = "/sc{empno}")
    @ResponseBody
    public int sc(@PathVariable("empno") int empno){
        return studentService.deleteByPrimaryKey(empno);
    }
}
